﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Config;
using LTJ.Common;
using LTJ.Entity;
using LTJ.FrameWork;

namespace LTJ.WebPage.UserManage.route
{
    /// <summary>
    /// 企业查看线路详细信息
    /// </summary>
    public partial class corproutedetail : UserPage
    {
        protected RouteBaseInfo rinfo = new RouteBaseInfo();
        protected int rid = SASRequest.GetInt("rid", 0);

        protected void Page_Load(object sender, EventArgs e)
        {
            rinfo = RouteBases.GetSearchRouteBaseInfo(rid, 2, companyinfo.id, -1);
        }

        /// <summary>
        /// 价格生成
        /// </summary>
        /// <param name="p1">底价</param>
        /// <param name="p2">港口价</param>
        /// <param name="p3">航线价</param>
        /// <returns></returns>
        protected string GetSeaPrice(string p1, string p2, string p3, string p4, string p5)
        {
            float price1 = TypeConverter.StrToFloat(p1, 0);
            int price2 = TypeConverter.StrToInt(p2, 0);
            int price3 = TypeConverter.StrToInt(p3, 0);
            int price4 = TypeConverter.StrToInt(p4, 0);
            int price5 = TypeConverter.StrToInt(p5, 0);

            if (price2 > 0) return (price1 + price2).ToString();
            else if (price3 > 0) return (price1 + price3).ToString();
            else if (price4 > 0) return (price1 + price4).ToString();
            else if (price5 > 0) return (price1 + price5).ToString();
            else return price1.ToString();
        }

        protected string GetSeaPrce(RouteBaseInfo priceinfo, int type)
        {
            float price1 = 0;

            if (type == 1)
            {
                price1 = TypeConverter.StrToFloat(priceinfo._20GP, 0);
                if (SumPrice(priceinfo._20GP1, priceinfo._40GP1, priceinfo._40HQ1) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._20GP1, 0);
                if (SumPrice(priceinfo._20GP2, priceinfo._40GP2, priceinfo._40HQ2) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._20GP2, 0);
                if (SumPrice(priceinfo._20GP5, priceinfo._40GP5, priceinfo._40HQ5) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._20GP5, 0);
                if (SumPrice(priceinfo._20GP6, priceinfo._40GP6, priceinfo._40HQ6) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._20GP6, 0);
                if (SumPrice(priceinfo._20GP3, priceinfo._40GP3, priceinfo._40HQ3) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._20GP3, 0);
                if (SumPrice(priceinfo._20GP4, priceinfo._40GP4, priceinfo._40HQ4) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._20GP4, 0);
            }
            else if (type == 2)
            {
                price1 = TypeConverter.StrToFloat(priceinfo._40GP, 0);
                if (SumPrice(priceinfo._20GP1, priceinfo._40GP1, priceinfo._40HQ1) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40GP1, 0);
                if (SumPrice(priceinfo._20GP2, priceinfo._40GP2, priceinfo._40HQ2) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40GP2, 0);
                if (SumPrice(priceinfo._20GP5, priceinfo._40GP5, priceinfo._40HQ5) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40GP5, 0);
                if (SumPrice(priceinfo._20GP6, priceinfo._40GP6, priceinfo._40HQ6) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40GP6, 0);
                if (SumPrice(priceinfo._20GP3, priceinfo._40GP3, priceinfo._40HQ3) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40GP3, 0);
                if (SumPrice(priceinfo._20GP4, priceinfo._40GP4, priceinfo._40HQ4) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40GP4, 0);
            }
            else if (type == 3)
            {
                price1 = TypeConverter.StrToFloat(priceinfo._40HQ, 0);
                if (SumPrice(priceinfo._20GP1, priceinfo._40GP1, priceinfo._40HQ1) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40HQ1, 0);
                if (SumPrice(priceinfo._20GP2, priceinfo._40GP2, priceinfo._40HQ2) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40HQ2, 0);
                if (SumPrice(priceinfo._20GP5, priceinfo._40GP5, priceinfo._40HQ5) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40HQ5, 0);
                if (SumPrice(priceinfo._20GP6, priceinfo._40GP6, priceinfo._40HQ6) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40HQ6, 0);
                if (SumPrice(priceinfo._20GP3, priceinfo._40GP3, priceinfo._40HQ3) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40HQ3, 0);
                if (SumPrice(priceinfo._20GP4, priceinfo._40GP4, priceinfo._40HQ4) > 0) price1 = price1 + TypeConverter.StrToInt(priceinfo._40HQ4, 0);
            }

            return price1.ToString();
        }

        private int SumPrice(string p1, string p2, string p3)
        {
            int price1 = TypeConverter.StrToInt(p1, 0);
            int price2 = TypeConverter.StrToInt(p2, 0);
            int price3 = TypeConverter.StrToInt(p3, 0);

            return price1 + price2 + price3;
        }

        /// <summary>
        /// 其他价格生成
        /// </summary>
        protected string GetOtherPrice(string price, int ordernum)
        {
            string[] pricearray = price.Split(',');

            if (pricearray.Length < 3) return "0";
            else return pricearray[ordernum - 1] == "" ? "0" : pricearray[ordernum - 1];
        }
    }
}